<extend name="./public/frame.html"/>
<block name="content">
    <style>
        .layui-form-label{width: 12%;}
        .layui-input-block{margin-left: 12%;}
    </style>
    <form class="layui-form layui-form-pane1" method="post" enctype="multipart/form-data">
        <table class="layui-table">
            <tr>
                <td colspan="2" style="font-weight: bold;color: black;">城际车队信息</td>
            </tr>
            <tr>
                <td>
                    <?php foreach($franchiseeList as $key=>$value):?>
                    <?php if(!empty($their_id)):?>
                    <input type="radio" name="their_id" value="<?php echo $value['their_id'];?>" title="<?php echo $value['their_name'];?>" <?php if($their_id == $value['their_id']):?>checked<?php endif;?>>
                    <?php else:?>
                    <input type="radio" name="their_id" value="<?php echo $value['their_id'];?>" title="<?php echo $value['their_name'];?>">
                    <?php endif;?>
                    <?php endforeach;?>
                </td>
            </tr>
            <!--<tr>
                <td style="width: 13%;text-align: center;">所属区域</td>
                <td>
                    <div class="layui-input-inline" style="width: 200px;margin-right: 5px;">
                        <select name="province_id" id="province_id" lay-verify="required" lay-filter="province">
                            <option value="">请选择省份</option>
                            <option value="0">默认省份</option>
                            <?php foreach($provinceList as $key=>$value):?>
                            <option value="<?php echo $value['region_id'];?>"><?php echo $value['region_name'];?></option>
                            <?php endforeach;?>
                        </select>
                    </div>
                    <div class="layui-input-inline" style="width: 200px;margin-right: 5px;">
                        <select name="city_id" id="city_id" lay-filter="city">
                            <option value="">请选择城市</option>
                            <option value="0">默认城市</option>
                        </select>
                    </div>
                </td>
            </tr>-->

            <tr>
                <td>
                    <input type="hidden" value="<?php echo $driver_id;?>" name="driver_id" id="driver_id">
                    <input type="hidden" value="<?php echo $driver_type;?>" name="driver_type" id="driver_type" />
                    <button class="layui-btn" lay-submit lay-filter="*">提交分配</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </td>
            </tr>
        </table>
    </form>
    <script>
        layui.use(['form'], function () {
            var form = layui.form;
            form.on('submit(*)', function(data){
                $.ajax({
                    url:'{:url("/admin/driver/distribute")}',
                    async:true,
                    dataType:'json',
                    type:'POST',
                    data: $(data.form).serialize(),
                    success:function(res){
                        if(res.code==1){
                            layer.alert(res.msg, {icon: 6},function () {
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(index);
                                window.parent.location.reload()
                            });
                        }else{
                            layer.msg(res.msg,{icon: 5});
                        }
                    }
                });
                return false;
            });
            form.on('select(province)', function(data){
                var province_id = data.value;
                if(province_id == 0){
                    $("#city_id").empty();
                    $("#city_id").append('<option value=0>默认城市</option>');
                    form.render('select');
                    return false;
                }
                $("#city_id").empty();
                $("#city_id").append('<option value=>请选择城市</option>');
                $.ajax({
                    url:'{:url("/admin/Franchisee/cityList")}',
                    async:true,
                    type:'post',
                    data:{'province_id':province_id},
                    success:function(res){
                        $("#city_id").append(res);
                        form.render('select');
                    },
                    error:function(e){
                        layer.msg('请求错误');return false;
                    }
                })
            });
        });
    </script>
</block>
